package com.nju.bean.newsbang.data;


public class Stack {
	public Stack( )
	{   this( DEFAULT_CAPACITY );
	}
    public Stack( int capacity )
    {   theArray = new String [capacity ];
    	topOfStack = -1;
    }
    public boolean isEmpty( ){ return topOfStack == -1; }
    public boolean isFull( ){ return topOfStack == theArray.length-1; }
    public void makeEmpty( ){ topOfStack = -1; }

    public void push( String x )
    {   if ( isFull( ) )
    	System.out.println("OverFlow");
    theArray[ ++topOfStack ] = x;
    }
    public String top( )
    {   if( isEmpty( ))
            return null;
         return theArray[ topOfStack ];
    }
    public String pop( ) 
    {   if( isEmpty( ) )
    	System.out.println("UnderFlow");
     String a=theArray[topOfStack];
     theArray[ topOfStack-- ] = null;
     return a;
    }
    public String topAndPop( )
    {   if( isEmpty( ) )
        return null;
     String topItem = top( );
     theArray[ topOfStack-- ] = null;
      return topItem;
    }
    public String getString(){
    	return theArray[topOfStack];
    }
    private String [ ] theArray;
    private int  topOfStack; 
    static final int DEFAULT_CAPACITY = 10;
}
